
package com.jf.cloud.product.service.impl;

import com.jf.cloud.common.cache.constant.CacheNames;
import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.util.PageUtil;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.product.mapper.SpuConsignmentChangeMapper;
import com.jf.cloud.product.model.SpuConsignmentChange;
import com.jf.cloud.product.service.SpuConsignmentChangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 商家代销商品基本信息相对于供应商品是否改变
 *
 * @author zz
 * @date 2022-08-11 22:21:10
 */
@Service
public class SpuConsignmentChangeServiceImpl implements SpuConsignmentChangeService {

    @Autowired
    private SpuConsignmentChangeMapper spuConsignmentChangeMapper;

    @Override
    public PageVO<SpuConsignmentChange> page(PageDTO pageDTO) {
        return PageUtil.doPage(pageDTO, () -> spuConsignmentChangeMapper.list());
    }

    @Override
    public SpuConsignmentChange getByConsignmentChangeId(Long consignmentChangeId) {
        return spuConsignmentChangeMapper.getByConsignmentChangeId(consignmentChangeId);
    }

    @Override
    public void save(SpuConsignmentChange spuConsignmentChange) {
        spuConsignmentChangeMapper.save(spuConsignmentChange);
    }

    @Override
    public void update(SpuConsignmentChange spuConsignmentChange) {
        spuConsignmentChangeMapper.update(spuConsignmentChange);
    }

    @Override
    public void deleteById(Long consignmentChangeId) {
        spuConsignmentChangeMapper.deleteById(consignmentChangeId);
    }

    @Override
    @Cacheable(cacheNames = CacheNames.SPU_SUPPLIER_CHANGE_LOG, key = "#spuId", sync = true)
    public SpuConsignmentChange getBySpuId(Long spuId) {
        return spuConsignmentChangeMapper.getBySpuId(spuId);
    }

    @Override
    public List<SpuConsignmentChange> batchGetBySpuIdList(List<Long> spuIdList) {
        if (spuIdList.size() == 0 || Objects.isNull(spuIdList)){
            return null;
        }
        return spuConsignmentChangeMapper.batchGetBySpuIdList(spuIdList);
    }

    @Override
    public SpuConsignmentChange consignmentChange(Long spuId) {
        return spuConsignmentChangeMapper.getBySpuId(spuId);
    }
}
